﻿<UserControl x:Class="Microsoft.Research.ScientificWorkflow.ManagementStudioControls.WorkflowManagerModule.AvailableWorkflowsListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" AutomationProperties.AutomationId="AvailableWorkflowsControl"
    xmlns:Controls="clr-namespace:Microsoft.Research.ScientificWorkflow.UIDesigner;assembly=Microsoft.Research.ScientificWorkflow.UIDesigner">
    <UserControl.Resources>
        <DataTemplate x:Key="ExpandToggleButton">
            <ToggleButton Content="ToggleButton" ToolTip="Show Jobs" Checked="ToggleButton_Checked" Unchecked="ToggleButton_Unchecked" Style="{DynamicResource ToggleButtonExpandCollapse}"/>
        </DataTemplate>
        <ContextMenu x:Key="EmptyContextMenu"/>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter"></BooleanToVisibilityConverter>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="25"/>
            <RowDefinition Height="36"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Border CornerRadius="5,5,0,0" Grid.Row="1">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFBFBFB" Offset="0"/>
                    <GradientStop Color="#FFF0F0F0" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <Grid>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                    <Button Style="{DynamicResource playbutton}" Width="26" Height="26" Command="{Binding Path=CreateJobCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}"  Margin="5,0,0,0" ToolTip="Run" AutomationProperties.AutomationId="ExecuteButton"/>
                    <Button Style="{DynamicResource ScheduleButton}" Width="26" Height="26" Command="{Binding Path=ScheduleWorkflowCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}" Margin="5,0,0,0" ToolTip="Schedule" AutomationProperties.AutomationId="ScheduleButton"/>
                    <Button Style="{DynamicResource resumeButton}" Width="26" Height="26" Command="{Binding Path=EditWorkflowCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}" Margin="5,0,0,0" ToolTip="Edit" AutomationProperties.AutomationId="EditButton"/>
                    <Button Style="{DynamicResource deleteButton}" Width="26" Height="26" Command="{Binding Path=DeleteWorkflowCommand}" CommandParameter="{Binding ElementName=DisplayListView, Path=SelectedItem}" Margin="5,0,0,0" ToolTip="Delete" AutomationProperties.AutomationId="DeleteButton"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <Button Style="{DynamicResource refreshButton}" Margin="0,0,10,0" Width="24" Height="24" Command="{Binding Path=RefreshListCommand}" ToolTip="Refresh" AutomationProperties.AutomationId="RefreshAvailableWorkflows"></Button>
                </StackPanel>
            </Grid>

        </Border>
        <Grid Grid.Row="2" Margin="5,10,5,5" Grid.RowSpan="2">
            <Controls:SortListView KeyDown="DisplayListView_KeyDown" SelectionMode="Single" SelectedIndex="{Binding Path=SelectedIndex}" ItemsSource="{Binding Path=Items}" Style="{DynamicResource ListViewStyle1}" ScrollViewer.CanContentScroll="True" x:Name="DisplayListView" IsSynchronizedWithCurrentItem="True" 
                                   ItemTemplate="{DynamicResource ParentDataTemplate}" Width="Auto" Height="Auto" SelectionChanged="DisplayListViewSelectionChanged">
                <Controls:SortListView.ItemContainerStyle>
                    <Style TargetType="{x:Type ListViewItem}">
                        <Setter Property="Template" Value="{StaticResource CompositeListViewItemControlTemplate}"/>
                        <Setter Property="ContextMenu" Value="{StaticResource EmptyContextMenu}"/>
                        <EventSetter Event="ContextMenuOpening" Handler="ContextMenu_ContextMenuOpening"></EventSetter>
                        <!--<EventSetter Event="MouseLeftButtonDown" Handler="ListViewItemClicked"></EventSetter>-->
                        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="PreviewListViewItemClicked"></EventSetter>
                        
                        <!--<EventSetter Event="MouseDoubleClick" Handler="ListViewItemDoubleClicked"></EventSetter>-->
                    </Style>
                </Controls:SortListView.ItemContainerStyle>
                <Controls:SortListView.View>
                <GridView>
                    <Controls:SortListViewColumn SortByDefault="True" DefaultSortDirection="Ascending" Width="150" MinimumWidth="130" SortProperty="Label" Header="Workflow Name" DisplayMemberBinding="{Binding Path=Label}" />
                    <Controls:SortListViewColumn MinimumWidth="100" Width="120" SortProperty="Author" Header="Author" DisplayMemberBinding="{Binding Path=Author}" />
                    <Controls:SortListViewColumn MinimumWidth="130" Width="130" SortProperty="CreatedTime" Header="Date Created" DisplayMemberBinding="{Binding Path=CreatedTime}" />
                    <Controls:SortListViewColumn MinimumWidth="130" Width="130" SortProperty="LastModifiedTime" Header="Date Modified" DisplayMemberBinding="{Binding Path=LastModifiedTime}" />
                    <Controls:SortListViewColumn MinimumWidth="200" Width="200" Header="Description" DisplayMemberBinding="{Binding Path=Description}" />
                    <Controls:SortListViewColumn MinimumWidth="40" Width="40" Header="Jobs" CellTemplate="{StaticResource ExpandToggleButton}" />
                </GridView>
                </Controls:SortListView.View>
            </Controls:SortListView>
            <Grid Background="White" Visibility="{Binding Converter={StaticResource VisibilityConverter}, Path=EmptyList}" Width="{Binding Path=Width, ElementName=ListviewHost}" Height="{Binding Path=Height, ElementName=ListviewHost}">
                <TextBlock HorizontalAlignment="Center" Foreground="Gray">No Items to be shown</TextBlock>
            </Grid>
        </Grid>
        <Border Margin="0,0,0,0" CornerRadius="5,5,0,0" BorderThickness="0,0,0,1" BorderBrush="#FFFFFFFF">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FFFFFFFF" Offset="0"/>
                    <GradientStop Color="#FFE8E8E8" Offset="1"/>
                </LinearGradientBrush>
            </Border.Background>
            <TextBlock Text="{Binding Path=ListViewTitle}" TextWrapping="Wrap" FontSize="14" FontWeight="Normal" Margin="7,2,0,0"/>
		</Border>
    </Grid>
</UserControl>
